<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>react设计的哲学 | aiyoudiao</title>
    <meta name="generator" content="VuePress 1.9.10" />
    <link rel="icon" href="/img/blog.ico">
    <script src="https://cdn.jsdelivr.net/npm/live2d-widget@3.1.4/lib/L2Dwidget.min.js"></script> <meta name="description" content="码二~">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,gitee,markdown">
    <meta name="theme-color" content="#11a8cd">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <link rel="preload" href="/assets/css/0.styles.146197cf.css" as="style"><link rel="preload" href="/assets/js/app.bd2fbc77.js" as="script"><link rel="preload" href="/assets/js/3.72c9c947.js" as="script"><link rel="preload" href="/assets/js/117.35ab1f9f.js" as="script"><link rel="preload" href="/assets/js/42.4251ca36.js" as="script"><link rel="prefetch" href="/assets/js/1.4ed4671d.js"><link rel="prefetch" href="/assets/js/10.bd6ddb58.js"><link rel="prefetch" href="/assets/js/100.20d2348f.js"><link rel="prefetch" href="/assets/js/101.ba7b784c.js"><link rel="prefetch" href="/assets/js/102.c3e2dcae.js"><link rel="prefetch" href="/assets/js/103.0f4c50f3.js"><link rel="prefetch" href="/assets/js/104.ef47a111.js"><link rel="prefetch" href="/assets/js/105.2e00f516.js"><link rel="prefetch" href="/assets/js/106.b50e19b9.js"><link rel="prefetch" href="/assets/js/107.e125a8f6.js"><link rel="prefetch" href="/assets/js/108.770493ab.js"><link rel="prefetch" href="/assets/js/109.74766d7b.js"><link rel="prefetch" href="/assets/js/11.f786a5ee.js"><link rel="prefetch" href="/assets/js/110.0b0ee5b4.js"><link rel="prefetch" href="/assets/js/111.835b0e44.js"><link rel="prefetch" href="/assets/js/112.352fa217.js"><link rel="prefetch" href="/assets/js/113.4e908557.js"><link rel="prefetch" href="/assets/js/114.7b77996d.js"><link rel="prefetch" href="/assets/js/115.bdc61268.js"><link rel="prefetch" href="/assets/js/116.d5da9b8b.js"><link rel="prefetch" href="/assets/js/118.517c151d.js"><link rel="prefetch" href="/assets/js/119.f7f49ba8.js"><link rel="prefetch" href="/assets/js/12.3c729a65.js"><link rel="prefetch" href="/assets/js/120.b559598b.js"><link rel="prefetch" href="/assets/js/121.bf8a2f43.js"><link rel="prefetch" href="/assets/js/122.11a0bc97.js"><link rel="prefetch" href="/assets/js/123.2bafdde7.js"><link rel="prefetch" href="/assets/js/124.dc393688.js"><link rel="prefetch" href="/assets/js/125.ed3f389a.js"><link rel="prefetch" href="/assets/js/126.8fd9a57d.js"><link rel="prefetch" href="/assets/js/127.3bf2a1f2.js"><link rel="prefetch" href="/assets/js/128.b9c671d3.js"><link rel="prefetch" href="/assets/js/129.5d331f0d.js"><link rel="prefetch" href="/assets/js/13.7b1a1fe5.js"><link rel="prefetch" href="/assets/js/130.53e4f9c6.js"><link rel="prefetch" href="/assets/js/131.dcc47e1d.js"><link rel="prefetch" href="/assets/js/132.692dcdcd.js"><link rel="prefetch" href="/assets/js/133.e293202c.js"><link rel="prefetch" href="/assets/js/134.593dccf2.js"><link rel="prefetch" href="/assets/js/135.d76d384b.js"><link rel="prefetch" href="/assets/js/136.a519c23c.js"><link rel="prefetch" href="/assets/js/137.b1821288.js"><link rel="prefetch" href="/assets/js/138.5bcea4ef.js"><link rel="prefetch" href="/assets/js/139.076664b0.js"><link rel="prefetch" href="/assets/js/14.35f257b2.js"><link rel="prefetch" href="/assets/js/140.a019e655.js"><link rel="prefetch" href="/assets/js/141.1f70e1c7.js"><link rel="prefetch" href="/assets/js/142.5ed728fd.js"><link rel="prefetch" href="/assets/js/143.1c8cdc78.js"><link rel="prefetch" href="/assets/js/144.b0cb125b.js"><link rel="prefetch" href="/assets/js/145.c0209a76.js"><link rel="prefetch" href="/assets/js/146.551469f4.js"><link rel="prefetch" href="/assets/js/147.1dfd721d.js"><link rel="prefetch" href="/assets/js/148.91d07ef5.js"><link rel="prefetch" href="/assets/js/149.5b88b710.js"><link rel="prefetch" href="/assets/js/15.23bbc29a.js"><link rel="prefetch" href="/assets/js/150.8301107f.js"><link rel="prefetch" href="/assets/js/151.867da089.js"><link rel="prefetch" href="/assets/js/152.935d5046.js"><link rel="prefetch" href="/assets/js/153.f39d8435.js"><link rel="prefetch" href="/assets/js/154.6b9eb2c3.js"><link rel="prefetch" href="/assets/js/155.14283ad4.js"><link rel="prefetch" href="/assets/js/156.2d7c1a2a.js"><link rel="prefetch" href="/assets/js/157.2f28d02f.js"><link rel="prefetch" href="/assets/js/158.151221ae.js"><link rel="prefetch" href="/assets/js/159.ef6d7ffe.js"><link rel="prefetch" href="/assets/js/16.1793aef7.js"><link rel="prefetch" href="/assets/js/160.de54c4ea.js"><link rel="prefetch" href="/assets/js/161.24d4e57c.js"><link rel="prefetch" href="/assets/js/162.632032fe.js"><link rel="prefetch" href="/assets/js/163.fd01cd99.js"><link rel="prefetch" href="/assets/js/164.45f203f5.js"><link rel="prefetch" href="/assets/js/165.aafe4fe1.js"><link rel="prefetch" href="/assets/js/166.1dd1d21c.js"><link rel="prefetch" href="/assets/js/167.5501b3a1.js"><link rel="prefetch" href="/assets/js/168.fbe58b1f.js"><link rel="prefetch" href="/assets/js/169.2cae7f5e.js"><link rel="prefetch" href="/assets/js/17.bbfe63f2.js"><link rel="prefetch" href="/assets/js/170.265f7c9e.js"><link rel="prefetch" href="/assets/js/171.b61f327d.js"><link rel="prefetch" href="/assets/js/172.5d0043fd.js"><link rel="prefetch" href="/assets/js/173.45284bb6.js"><link rel="prefetch" href="/assets/js/174.9130e0c4.js"><link rel="prefetch" href="/assets/js/175.2b38bddd.js"><link rel="prefetch" href="/assets/js/176.9772cf09.js"><link rel="prefetch" href="/assets/js/177.69048ebc.js"><link rel="prefetch" href="/assets/js/178.e10d7ce5.js"><link rel="prefetch" href="/assets/js/179.3789edc0.js"><link rel="prefetch" href="/assets/js/18.0807ded0.js"><link rel="prefetch" href="/assets/js/180.ab675e47.js"><link rel="prefetch" href="/assets/js/181.2e39eff0.js"><link rel="prefetch" href="/assets/js/19.becf5a76.js"><link rel="prefetch" href="/assets/js/2.eb089a4f.js"><link rel="prefetch" href="/assets/js/20.cea59652.js"><link rel="prefetch" href="/assets/js/21.58c43ff1.js"><link rel="prefetch" href="/assets/js/22.f73b825d.js"><link rel="prefetch" href="/assets/js/23.43b13730.js"><link rel="prefetch" href="/assets/js/24.f77f93ca.js"><link rel="prefetch" href="/assets/js/25.7dfaf3fb.js"><link rel="prefetch" href="/assets/js/26.629d28e5.js"><link rel="prefetch" href="/assets/js/27.4fff23ea.js"><link rel="prefetch" href="/assets/js/28.1b8ae389.js"><link rel="prefetch" href="/assets/js/29.d5cce9a0.js"><link rel="prefetch" href="/assets/js/30.961d5519.js"><link rel="prefetch" href="/assets/js/31.121dd1af.js"><link rel="prefetch" href="/assets/js/32.4a3c5df7.js"><link rel="prefetch" href="/assets/js/33.5537f44b.js"><link rel="prefetch" href="/assets/js/34.1d4d4653.js"><link rel="prefetch" href="/assets/js/35.d094209b.js"><link rel="prefetch" href="/assets/js/36.832660c5.js"><link rel="prefetch" href="/assets/js/37.145c3665.js"><link rel="prefetch" href="/assets/js/38.4f369bfe.js"><link rel="prefetch" href="/assets/js/39.ba060044.js"><link rel="prefetch" href="/assets/js/4.66d742f6.js"><link rel="prefetch" href="/assets/js/40.e50e0379.js"><link rel="prefetch" href="/assets/js/41.4ed7617c.js"><link rel="prefetch" href="/assets/js/43.d22b74c4.js"><link rel="prefetch" href="/assets/js/44.59439f9d.js"><link rel="prefetch" href="/assets/js/45.da28bc46.js"><link rel="prefetch" href="/assets/js/46.b8db1176.js"><link rel="prefetch" href="/assets/js/47.7ed16fc7.js"><link rel="prefetch" href="/assets/js/48.c982d5ed.js"><link rel="prefetch" href="/assets/js/49.a7579f55.js"><link rel="prefetch" href="/assets/js/5.08802d7d.js"><link rel="prefetch" href="/assets/js/50.103b5bf6.js"><link rel="prefetch" href="/assets/js/51.0fe9d79a.js"><link rel="prefetch" href="/assets/js/52.9ba31e26.js"><link rel="prefetch" href="/assets/js/53.0e8bc1f0.js"><link rel="prefetch" href="/assets/js/54.9566e517.js"><link rel="prefetch" href="/assets/js/55.a124abae.js"><link rel="prefetch" href="/assets/js/56.d9cf0800.js"><link rel="prefetch" href="/assets/js/57.93599da0.js"><link rel="prefetch" href="/assets/js/58.d943f85b.js"><link rel="prefetch" href="/assets/js/59.50a66488.js"><link rel="prefetch" href="/assets/js/6.a3ea60eb.js"><link rel="prefetch" href="/assets/js/60.21aa3aa3.js"><link rel="prefetch" href="/assets/js/61.6712c00f.js"><link rel="prefetch" href="/assets/js/62.eff3e4b1.js"><link rel="prefetch" href="/assets/js/63.09701d5a.js"><link rel="prefetch" href="/assets/js/64.eb440dec.js"><link rel="prefetch" href="/assets/js/65.aeed0579.js"><link rel="prefetch" href="/assets/js/66.97244c64.js"><link rel="prefetch" href="/assets/js/67.e01c5c24.js"><link rel="prefetch" href="/assets/js/68.21be91ba.js"><link rel="prefetch" href="/assets/js/69.c0849905.js"><link rel="prefetch" href="/assets/js/7.7fd40e91.js"><link rel="prefetch" href="/assets/js/70.b32bbe5d.js"><link rel="prefetch" href="/assets/js/71.0efbc0c7.js"><link rel="prefetch" href="/assets/js/72.ef963181.js"><link rel="prefetch" href="/assets/js/73.ca7dd5db.js"><link rel="prefetch" href="/assets/js/74.4483ede8.js"><link rel="prefetch" href="/assets/js/75.374ab483.js"><link rel="prefetch" href="/assets/js/76.b4a39f08.js"><link rel="prefetch" href="/assets/js/77.6b30c3cd.js"><link rel="prefetch" href="/assets/js/78.15376c33.js"><link rel="prefetch" href="/assets/js/79.3153fcec.js"><link rel="prefetch" href="/assets/js/80.9a88c684.js"><link rel="prefetch" href="/assets/js/81.1e3f842c.js"><link rel="prefetch" href="/assets/js/82.996dbd3d.js"><link rel="prefetch" href="/assets/js/83.955158bf.js"><link rel="prefetch" href="/assets/js/84.71bdc76d.js"><link rel="prefetch" href="/assets/js/85.774e49f2.js"><link rel="prefetch" href="/assets/js/86.bebf32e5.js"><link rel="prefetch" href="/assets/js/87.becdbde1.js"><link rel="prefetch" href="/assets/js/88.49e933f4.js"><link rel="prefetch" href="/assets/js/89.eeceedfd.js"><link rel="prefetch" href="/assets/js/90.3ea6dd12.js"><link rel="prefetch" href="/assets/js/91.62a6a556.js"><link rel="prefetch" href="/assets/js/92.e2ebb8f5.js"><link rel="prefetch" href="/assets/js/93.dcdefe7a.js"><link rel="prefetch" href="/assets/js/94.bf412146.js"><link rel="prefetch" href="/assets/js/95.8deadcdc.js"><link rel="prefetch" href="/assets/js/96.9977087a.js"><link rel="prefetch" href="/assets/js/97.6591f9da.js"><link rel="prefetch" href="/assets/js/98.4db7f75e.js"><link rel="prefetch" href="/assets/js/99.a61462e9.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.2852b102.js"> <link rel="stylesheet" href="/assets/css/0.styles.146197cf.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" width="50" height="50" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="https://p3-passport.byteacctimg.com/img/user-avatar/794fdae4ff249d532da19a3c26d420ed~300x300.image" alt="aiyoudiao" class="logo"> <span class="site-name can-hide">
      aiyoudiao
    </span></a> <div class="links"><div class="sky-switch" data-v-3a03d589><label for="toggle" data-v-3a03d589><input id="toggle" type="checkbox" data-v-3a03d589><div data-v-3a03d589></div></label></div> <div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="笔记" class="dropdown-title"><!----> <span class="title" style="display:;">笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/84633490449/" class="nav-link">
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/pages/2331001041/" class="nav-link">
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/pages/18114480448/" class="nav-link">
  React
</a></li><li class="dropdown-item"><!----> <a href="/pages/25236260426/" class="nav-link">
  低代码
</a></li><li class="dropdown-item"><!----> <a href="/pages/35345230523/" class="nav-link">
  线性系统
</a></li><li class="dropdown-item"><!----> <a href="/pages/08313561056/" class="nav-link">
  暂未分类
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法与设计" class="dropdown-title"><!----> <span class="title" style="display:;">算法与设计</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/70741550255/" class="nav-link">
  LeetCode
</a></li><li class="dropdown-item"><!----> <a href="/pages/17845450445/" class="nav-link">
  算法
</a></li><li class="dropdown-item"><!----> <a href="/pages/90132170217/" class="nav-link">
  数据结构
</a></li><li class="dropdown-item"><!----> <a href="/pages/50546120212/" class="nav-link">
  设计模式
</a></li><li class="dropdown-item"><!----> <a href="/pages/02344550255/" class="nav-link">
  Other
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技能" class="dropdown-title"><!----> <span class="title" style="display:;">技能</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/82158160216/" class="nav-link">
  PMP
</a></li><li class="dropdown-item"><!----> <a href="/pages/41858590259/" class="nav-link">
  Office
</a></li><li class="dropdown-item"><!----> <a href="/pages/02359360236/" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/pages/73600130213/" class="nav-link">
  Bash
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="历程" class="dropdown-title"><!----> <span class="title" style="display:;">历程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/83857320232/" class="nav-link">
  流年往事
</a></li><li class="dropdown-item"><!----> <a href="/pages/93419130213/" class="nav-link">
  经验片段
</a></li><li class="dropdown-item"><!----> <a href="/pages/99744220322/" class="nav-link">
  读书杂感
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="首页" class="dropdown-title"><!----> <span class="title" style="display:;">首页</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">
  归档
</a></li><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">
  分类
</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">
  标签
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="其它" class="dropdown-title"><!----> <span class="title" style="display:;">其它</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/02657130213/" class="nav-link">
  简介
</a></li><li class="dropdown-item"><!----> <a href="/pages/5390102042/" class="nav-link">
  收藏
</a></li><li class="dropdown-item"><!----> <a href="/pages/32309510451/" class="nav-link">
  有趣
</a></li><li class="dropdown-item"><!----> <a href="/pages/23313210521/" class="nav-link">
  文档
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/img/mar.jpg"> <div class="blogger-info"><h3>码二</h3> <span>扫微信二维码，认识一下码二吧😉。</span></div></div> <nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="笔记" class="dropdown-title"><!----> <span class="title" style="display:;">笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/84633490449/" class="nav-link">
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/pages/2331001041/" class="nav-link">
  Vue
</a></li><li class="dropdown-item"><!----> <a href="/pages/18114480448/" class="nav-link">
  React
</a></li><li class="dropdown-item"><!----> <a href="/pages/25236260426/" class="nav-link">
  低代码
</a></li><li class="dropdown-item"><!----> <a href="/pages/35345230523/" class="nav-link">
  线性系统
</a></li><li class="dropdown-item"><!----> <a href="/pages/08313561056/" class="nav-link">
  暂未分类
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="算法与设计" class="dropdown-title"><!----> <span class="title" style="display:;">算法与设计</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/70741550255/" class="nav-link">
  LeetCode
</a></li><li class="dropdown-item"><!----> <a href="/pages/17845450445/" class="nav-link">
  算法
</a></li><li class="dropdown-item"><!----> <a href="/pages/90132170217/" class="nav-link">
  数据结构
</a></li><li class="dropdown-item"><!----> <a href="/pages/50546120212/" class="nav-link">
  设计模式
</a></li><li class="dropdown-item"><!----> <a href="/pages/02344550255/" class="nav-link">
  Other
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技能" class="dropdown-title"><!----> <span class="title" style="display:;">技能</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/82158160216/" class="nav-link">
  PMP
</a></li><li class="dropdown-item"><!----> <a href="/pages/41858590259/" class="nav-link">
  Office
</a></li><li class="dropdown-item"><!----> <a href="/pages/02359360236/" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/pages/73600130213/" class="nav-link">
  Bash
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="历程" class="dropdown-title"><!----> <span class="title" style="display:;">历程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/83857320232/" class="nav-link">
  流年往事
</a></li><li class="dropdown-item"><!----> <a href="/pages/93419130213/" class="nav-link">
  经验片段
</a></li><li class="dropdown-item"><!----> <a href="/pages/99744220322/" class="nav-link">
  读书杂感
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="首页" class="dropdown-title"><!----> <span class="title" style="display:;">首页</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">
  归档
</a></li><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">
  分类
</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">
  标签
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="其它" class="dropdown-title"><!----> <span class="title" style="display:;">其它</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/02657130213/" class="nav-link">
  简介
</a></li><li class="dropdown-item"><!----> <a href="/pages/5390102042/" class="nav-link">
  收藏
</a></li><li class="dropdown-item"><!----> <a href="/pages/32309510451/" class="nav-link">
  有趣
</a></li><li class="dropdown-item"><!----> <a href="/pages/23313210521/" class="nav-link">
  文档
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>react</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><section class="sidebar-group collapsable is-sub-group depth-1"><p class="sidebar-heading open"><span>16_4</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/18114480448/" class="sidebar-link">React16_4整理-开篇</a></li><li><a href="/pages/78144320432/" class="sidebar-link">React16_4整理-TodoList</a></li><li><a href="/pages/7981309049/" class="sidebar-link">React16_4整理-上阶</a></li><li><a href="/pages/4241004044/" class="sidebar-link">React16_4整理-Redux开篇</a></li><li><a href="/pages/2765901041/" class="sidebar-link">React16_4整理-Redux上阶</a></li><li><a href="/pages/53933290429/" class="sidebar-link">React16_4整理-实战</a></li></ul></section></li><li><a href="/pages/2541802042/" class="sidebar-link">react心得</a></li><li><a href="/pages/56216400440/" aria-current="page" class="active sidebar-link">react设计的哲学</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/56216400440/#前言" class="sidebar-link">前言</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#组件的组成部分应该要放到一起" class="sidebar-link">组件的组成部分应该要放到一起</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#分层思维和组件化思维" class="sidebar-link">分层思维和组件化思维</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#公共的东西一定是少数" class="sidebar-link">公共的东西一定是少数</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#通过组件化的方式让你的压力变小" class="sidebar-link">通过组件化的方式让你的压力变小</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#组件化聚焦在一个页面的组合" class="sidebar-link">组件化聚焦在一个页面的组合</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/56216400440/#两种分析方式" class="sidebar-link">两种分析方式</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#拆分要考虑的" class="sidebar-link">拆分要考虑的</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#三种特性" class="sidebar-link">三种特性</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#做好拆分" class="sidebar-link">做好拆分</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#封装" class="sidebar-link">封装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/56216400440/#封装的逻辑" class="sidebar-link">封装的逻辑</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#封装的好处" class="sidebar-link">封装的好处</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#不封装的坏处" class="sidebar-link">不封装的坏处</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#不可过度封装" class="sidebar-link">不可过度封装</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#数据驱动ui" class="sidebar-link">数据驱动UI</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/56216400440/#不同角度的解读" class="sidebar-link">不同角度的解读</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#总结" class="sidebar-link">总结</a></li><li class="sidebar-sub-header"><a href="/pages/56216400440/#其它" class="sidebar-link">其它</a></li></ul></li><li><a href="/pages/64353330433/" class="sidebar-link">react上手知识点(上篇)</a></li><li><a href="/pages/67517390439/" class="sidebar-link">react上手知识点(下篇)</a></li><li><a href="/pages/21029430543/" class="sidebar-link">antd</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>低代码</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>读书会</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>线性代数</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>docker</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>auto</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>杂记</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"> <div class="theme-vdoing-wrapper bg-style-1"><div class="articleInfo-wrap" data-v-18fb2c02><div class="articleInfo" data-v-18fb2c02><ul class="breadcrumbs" data-v-18fb2c02><li data-v-18fb2c02><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-18fb2c02></a></li> <li data-v-18fb2c02><a href="/categories/?category=%E7%AC%94%E8%AE%B0" title="分类" data-v-18fb2c02>
          笔记
        </a></li> <li data-v-18fb2c02><a href="/categories/?category=react" title="分类" data-v-18fb2c02>
          react
        </a></li> <!----></ul> <div class="info" data-v-18fb2c02><div title="作者" class="author iconfont icon-touxiang" data-v-18fb2c02><a href="javascript:;" data-v-18fb2c02>aiyoudiao</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-18fb2c02><a href="javascript:;" data-v-18fb2c02>2022-04-13</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-content"></div></div></div> <h1><!----> <span>
            react设计的哲学
          </span></h1> <div class="theme-vdoing-content content__default"><h2 id="前言"><a href="#前言" class="header-anchor">#</a> 前言</h2> <p>react 是一个视图层的类库，主要是做dom渲染和响应事件的事情，如果想更高的把控它，可以有脱离基础语法束缚的哲学，从而能够站的更高。</p> <h2 id="组件的组成部分应该要放到一起"><a href="#组件的组成部分应该要放到一起" class="header-anchor">#</a> 组件的组成部分应该要放到一起</h2> <p>组件化的文件结构应该是 按照功能进行分类，然后每一个功能的组件中包含 api、store、css、入口文件、类型声明、枚举文件文件等等，应该要放到一起去。这样的话，找和它相关的文件，就会非常的简单。这样开发起来就能减少心智层面的压力，比如这时候有人打乱你的思路时，你也能很快的找到相应的目录及文件。</p> <p>比如下图所示：</p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649850599828-63582e27-4d73-4b15-8529-97b3e4f9b118.png" alt=""></p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649850614354-494a9e19-7f47-4297-8ea2-873250e65e83.png" alt=""></p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649850630812-a70edbe4-fe70-4e5a-bc1a-646b0e13758f.png" alt=""></p> <h2 id="分层思维和组件化思维"><a href="#分层思维和组件化思维" class="header-anchor">#</a> 分层思维和组件化思维</h2> <p>分层思维是从后端传过来的，后端他写一个接口不会占用太多的文件，而前端一个组件或者页面会占用很多的文件，所以是有不一样的地方。<br>
通过组件化的目录结构，可以有效的避免项目升级或者拷贝到一个新的相似功能的位置去时出现大量的变动，直接拷贝组件的目录结构即可，工作量会很小。</p> <h2 id="公共的东西一定是少数"><a href="#公共的东西一定是少数" class="header-anchor">#</a> 公共的东西一定是少数</h2> <p>公共的东西可以使用分层的思维。</p> <p>如下图：</p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649851459745-448fe782-6c6e-4908-8afe-f44520b95b4c.png" alt=""></p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649851484155-7afc6f37-e1c1-41e4-ac47-0aea2c499dee.png" alt=""></p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649851504702-5f72a2ad-57a8-4b35-af2c-45dcd866f5de.png" alt=""></p> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649851565257-c53c96a3-fc68-4977-aeba-e2bc31e8af57.png" alt=""></p> <h2 id="通过组件化的方式让你的压力变小"><a href="#通过组件化的方式让你的压力变小" class="header-anchor">#</a> 通过组件化的方式让你的压力变小</h2> <p>通过给公共的东西进行分层和非公共的东西进行组件化这样的设计，分层的目录结构和组件化的目录结构混合在一起用，可以让你用起来的压力很小，同时让你的工作效率高很多，如果你有两个显示器的话，不太会发生你把页面切换来切换去、闪来闪去的问题。</p> <h2 id="组件化聚焦在一个页面的组合"><a href="#组件化聚焦在一个页面的组合" class="header-anchor">#</a> 组件化聚焦在一个页面的组合</h2> <p><img src="https://gitee.com/aiyoudiao/images/raw/master/2022/04/13/1649851891895-617ffc03-b392-484e-a6d9-4e2187961908.png" alt=""></p> <p>组件化提供的是一种思路 ，如何去简化这个项目，一个如何去拆分这个项目的思路，当你看到这个页面的时候，你就能想到可以把它怎么样去拆分。<br>
这样一来它和html的布局就非常的像了，比如你去写一个页面的布局的时候，怎么写比较方便。做拆分的时候去分析它的页面结构以及布局特点。</p> <h3 id="两种分析方式"><a href="#两种分析方式" class="header-anchor">#</a> 两种分析方式</h3> <p>左右结构 和 上下结构，分析了布局的特点，机会决定你怎么去写布局，它的拆分决定了你写布局。这种拆分和你写html布局很像。如果你拆分的不好，那么也会决定你布局写的不好。那么你CSS那里就需要再提高一些。</p> <h3 id="拆分要考虑的"><a href="#拆分要考虑的" class="header-anchor">#</a> 拆分要考虑的</h3> <p>拆分第一个要考虑的是基于布局，第二个要考虑的是基于交互特性。做拆分的时候要考虑一些小的细节，你不仅要考虑你看到的那些部分，你也要考虑你没看到的那部分。它是一整个项目，它不是单个项目。<br>
所以整体来说需要思考他的交互之后，把它的特性分析完毕之后，再去考虑拆分。如果它的布局特性你没有分析完整，你就做拆分，很有可能导致你做的东西会带来某些功能或者需求实现不了或者非常难以实现。</p> <h3 id="三种特性"><a href="#三种特性" class="header-anchor">#</a> 三种特性</h3> <p>理解组件化的时候，分析清楚所有的特性，布局特性、交互特性、数据特性，分析完整之后你再去设计，否则会导致你思考出来的拆分可能有问题。拆分有问题，就会导致你实现起来很困难。<br>
尽量的不要去漏掉一些已知条件，漏掉这些已知条件，那么你就会出现问题。<br>
如果你发现你的解决方案太复杂了，你就回头想想是不是你拆分的有问题。多想一想</p> <h3 id="做好拆分"><a href="#做好拆分" class="header-anchor">#</a> 做好拆分</h3> <p>拆分做好了之后，你就可以有序的把任务进行一个拆解，这样你分任务的时候就很简单，这时候你搭个架子就行，就算是你自己去实现也会很顺手。<br>
先思考拆分再组合在一起。</p> <h2 id="封装"><a href="#封装" class="header-anchor">#</a> 封装</h2> <p>封装是一个基本技能，如果这个基本技能没有弄清楚，学任何框架都是白搭，学啥都会很累。想变成一个高手并不是学很多个框架，如果你掌握了上面的拆分以及现在的封装，变成一个高手其实很简单。</p> <h3 id="封装的逻辑"><a href="#封装的逻辑" class="header-anchor">#</a> 封装的逻辑</h3> <p>先搞清楚你为什么要去做封装，封装并不光是为了复用，更多的是为了简化代码。把代码给简化了，这样可读性才好。</p> <p>封装类似的代码，当某些代码出现了太多次，你就会想不去写太多次，从而进行封装。这时候你就需要去分析它出现的这些场景，找到它们的共性和差异性。<br>
共性就是把相同的代码都给它封装到函数中，而差异性就是通过参数传入到函数里面，然后差异部分的参数与函数里的共性部分组合起来，最后就完成了这些场景中都能使用的功能函数封装。<br>
当你对场景认识的不够，你封装出来的东西就会有问题，因为你封装出来的不能适应这些场景，所以可能会导致你重写。</p> <p>对场景分析透彻很重要。搞清楚差异性，对参数的设计就是找出差异性。封装对象、函数、组件都是通过传参的方式，可能传参的方式不一样，但是归根结底是一样的，其中的参数设计就是在找它的一个差异性。</p> <p>把简化代码提高可读性 和 通过共性、差异性来封装代码提高代码复用 这两点掌握好把控好，实际上封装就非常的简单了。</p> <h3 id="封装的好处"><a href="#封装的好处" class="header-anchor">#</a> 封装的好处</h3> <p>当代码复杂了，可读性不好了，你就会去想着去封装一下代码，复用不复用其实并不是很重要，主要是代码简化了，让代码读起来更简单、很舒服，一看就知道1234干了什么，这样开发起来效率更高，心智压力更小。</p> <p>把重复出现多的地方进行封装，把其中共性(一样)的东西封装成组件或者函数，把其中差异性(不一样)的东西设计成参数。不同的场景看你自己的一个积累，把所有场景找准，再去思考封装，这样你的代码重构或者重写的概率就会小一些。</p> <p>如果你以简化代码的角度出发，你就不会出现几万行代码在一个文件中。正常情况下一个文件三四百行代码就已经不少了，一两百行就最好了，这样你的大多数组件就会读起来非常的简单。</p> <p>维护的时候逻辑清晰，快速定位问题源头。</p> <h3 id="不封装的坏处"><a href="#不封装的坏处" class="header-anchor">#</a> 不封装的坏处</h3> <p>几千行几万行代码的一个文件，是非常难维护的，改个需求、修复个bug头疼死人了。如果好维护的话，改个bug几分钟就能改完。<br>
如果不好维护的话，改个bug就要几个小时甚至更长，甚至你还提心吊胆的，各种反复的验证，不知道它改对了没有。</p> <h3 id="不可过度封装"><a href="#不可过度封装" class="header-anchor">#</a> 不可过度封装</h3> <p>如果你的代码很简单，一般情况下就没必要去封装它。封装是为了简化代码，并不是去复杂化代码然后让代码阅读起来更加困难。</p> <h2 id="数据驱动ui"><a href="#数据驱动ui" class="header-anchor">#</a> 数据驱动UI</h2> <p>组件化的框架就是数据驱动UI的，如React，dom操作由框架去完成，而你只需要关注数据，因为数据和UI之间建立了一个联系，通过操作这个数据，UI就能够自动进行变化。</p> <h3 id="不同角度的解读"><a href="#不同角度的解读" class="header-anchor">#</a> 不同角度的解读</h3> <p>数据驱动，要清楚驱动UI的数据是哪些数据，驱动UI的数据和不需要驱动UI的数据分开。需要驱动UI的数据就放到react的state或者vue的data中去。这样就能减少数据监听时带来的性能损耗以及阅读代码时的一些误导，因为不需要驱动UI的数据没必要放到数据监听的地方。</p> <p>开发的时候大都是先看到UI，后看到数据，那么你就需要去分析这个UI可能会带来哪些数据。比如 列表 这样的UI，你肯定能想到它是一个数组。还有选项卡这样的UI，它的数据应该是什么样的。<br>
先分析出来，它是由什么样的数据结构组成，它有什么样的特性，怎么去操作这样的数据，从而思考出解决方案，最后就知道如何去用数据驱动UI了。</p> <p>开发思维的代数效应，通过数据的变化驱动另外一个数据的变化，再用被驱动的数据来驱动UI，类似vue中的computed 或者 watch以及react中的useEffect。<br>
当项目中的数据有很多，从而变的很复杂，这时候可以提炼出一个数据，让这个简单的数据被那几个复杂的数据驱动，从而使用这个简单的数据来驱动UI，这就是聚合。<br>
也可以让这个简单的数据去驱动那几个复杂的数据，从而使用复杂的数据去驱动UI，都是可以的。比如页面是否刷新，一刷新，所有数据都会重新赋值，然后UI就会重新渲染。</p> <h2 id="总结"><a href="#总结" class="header-anchor">#</a> 总结</h2> <p>很多东西就是一个认知的问题，有了这个认知你才能少走很多弯路。</p> <p>推荐这篇<a href="https://www.joshwcomeau.com/react/file-structure/" target="_blank" rel="noopener noreferrer">令人愉快的 React 文件/目录结构<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，也很不错哟。</p> <h2 id="其它"><a href="#其它" class="header-anchor">#</a> 其它</h2> <p>dva 聚合了redux了一些功能。</p> <p>umi 挺好用的</p> <p>react 18 其实不是给普通用户用的，实际上是给底层开发、工具开发，它可能会用到一些并发的模式。</p> <p>ref 和 memo 都是缓存数据，都是闭包</p> <p>redux-toolkit：Redux 工具包，官方的。<a href="https://github.com/reduxjs/redux-toolkit" target="_blank" rel="noopener noreferrer">https://github.com/reduxjs/redux-toolkit<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></div></div> <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=react" title="标签">#react</a></div> <div class="last-updated"><span class="prefix">上次更新时间:</span> <span class="time">10年18月2023日 01时57分53秒</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/2541802042/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">react心得</div></a> <a href="/pages/64353330433/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">react上手知识点(上篇)</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/2541802042/" class="prev">react心得</a></span> <span class="next"><a href="/pages/64353330433/"> react上手知识点(上篇) </a>
        →
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/45343271027/"><div>01.数据结构导论一览.md</div></a> <span>10-16</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/38850370637/"><div>30.2023年06月04日.md</div></a> <span>06-04</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/74707370537/"><div>08.与测量相关.md</div></a> <span>05-06</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div> </main></div> <div class="footer"><!----> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2017-2023
    <span class="link">aiyoudiao 码二</span> <span>备案号：</span> <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank" title="备案号">鄂ICP备2022002654号-1</a></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div><APlayer audio="" fixed="true" theme="#b7daff" loop="loop" order="list" preload="auto" volume="0.7" mutex="true" lrc-type="3" list-max-height="250" storage-name="vuepress-plugin-meting" id="aplayer-fixed"></APlayer><div id="VuepressPluginLive2d"></div></div></div>
    <script src="/assets/js/app.bd2fbc77.js" defer></script><script src="/assets/js/3.72c9c947.js" defer></script><script src="/assets/js/117.35ab1f9f.js" defer></script><script src="/assets/js/42.4251ca36.js" defer></script>
  </body>
</html>
